package com.techfengs.chapter03;

public class StringToBasic {
  public static void main (String[] args) {
    // 基本数据类型转String
    int n1 = 100;
    float f1 = 1.1F;
    double d1 = 4.5;
    boolean b1 = true;

    String s1 = n1+"";
    String s2 = f1+"";
    String s3 = d1+"";
    String s4 = b1+"";
    System.out.println(s1);
    System.out.println(s2);
    System.out.println(s3);
    System.out.println(s4);

    // String转基本数据类型
    String s5 = "123";
    int num1 = Integer.parseInt(s5);
    double num2 = Double.parseDouble(s5);
    float num3 = Float.parseFloat(s5);
    long num4 = Long.parseLong(s5);
    byte num5 = Byte.parseByte(s5);
    boolean num6 = Boolean.parseBoolean("true");
    short num7 = Short.parseShort(s5);
    System.out.println(num1);
    System.out.println(num2);
    System.out.println(num3);
    System.out.println(num4);
    System.out.println(num5);
    System.out.println(num6);
    System.out.println(num7);

    // 怎么把字符串转成字符？
    // 从字符串中取出字符
    char a1 = s5.charAt(0);
    System.out.println(a1);
  }
}
